package com.hksj.data.tdengine.conf;

import com.hksj.data.tdengine.operation.TDengineOperations;
import com.hksj.data.tdengine.restful.query.RestfulTDengineDataQuerier;
import com.hksj.data.tdengine.operation.DefaultTDengineOperationsAdapter;
import com.hksj.data.tdengine.restful.write.SchemalessTDengineDataWriter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zengke
 * @version 1.0
 * @see TDengineConfiguration
 * @since 2025/08/14 16:48
 */
@Configuration
@ConditionalOnProperty(prefix = "hk.tdengine",name = "enable",havingValue = "true")
@EnableConfigurationProperties(TDengineProperties.class)
public class TDengineConfiguration {

    @Bean
    public TDengineOperations tdengineOperations(TDengineProperties properties) {

        //初始化连接
        TDengineProperties.RestfulConnector connector = properties.getRestful().init();

        SchemalessTDengineDataWriter writer = new SchemalessTDengineDataWriter(connector,properties.getDatabase());

        return new DefaultTDengineOperationsAdapter(writer,new RestfulTDengineDataQuerier(connector,properties.getDatabase()));
    }
}
